{% extends "base_generic.html" %}

{% block content %}
<div class="container mt-4">
    <div class="card">
        <div class="card-header bg-primary text-white">
            <h1 class="mb-0"><i class="fas fa-user"></i> 作者: {{ author }}</h1>
        </div>
        <div class="card-body">
            <p class="text-muted">{{author.date_of_birth}} - {% if author.date_of_death %}{{author.date_of_death}}{% endif %}</p>
            
            {% if perms.catalog.change_author or perms.catalog.delete_author %}
            <div class="mb-4">
                {% if perms.catalog.change_author %}
                    <a href="{% url 'author-update' author.id %}" class="btn btn-primary"><i class="fas fa-edit"></i> 更新作者</a>
                {% endif %}
                {% if not author.book_set.all and perms.catalog.delete_author %}
                    <a href="{% url 'author-delete' author.id %}" class="btn btn-danger ms-2"><i class="fas fa-trash"></i> 删除作者</a>
                {% endif %}
            </div>
            {% endif %}
            
            <div class="mt-4">
                <h4><i class="fas fa-book"></i> 书籍列表</h4>
                
                <div class="list-group">
                {% for book in author.book_set.all %}
                    <div class="list-group-item">
                        <div class="d-flex w-100 justify-content-between">
                            <h5 class="mb-1"><a href="{% url 'book-detail' book.pk %}">{{book}}</a></h5>
                            <small class="badge bg-primary rounded-pill">{{book.bookinstance_set.all.count}} 本</small>
                        </div>
                        <p class="mb-1">{{book.summary}}</p>
                    </div>
                {% empty %}
                    <div class="alert alert-info">该作者暂无书籍。</div>
                {% endfor %}
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block sidebar %}
  {{ block.super }}
{% endblock %}